import React from 'react';
import ReactDOM from 'react-dom';
import CMPToat from './Toast';

// let toast = null;
// let div = [];

const show = (str, wait = 3000) => {
  let div = null;
  div = document.createElement('div');
  document.body.appendChild(div);

  const close = () => {
    if (div) {
      ReactDOM.unmountComponentAtNode(div);
      document.body.removeChild(div);
      div = null;
    }
  };

  ReactDOM.render(<CMPToat content={str} wait={wait} onClose={close}></CMPToat>, div);
}

let Toast = {};
Toast.show = show;

export default Toast;